import time
from prg.common.object_message import MessageBase
from prg.entity.public_entity import PublicEntity


class RunCommand(MessageBase):
    def __init__(self, name="run_command"):
        super().__init__(name=name)
        self.command_queue = PublicEntity.instance().command

    def add(self, cmd):
        self.command_queue.put(cmd)

    def get_queue(self):
        return self.command_queue

    def entry(self):
        while self.is_run():
            if not self.command_queue.empty():
                print("command list length: %d" % self.command_queue.qsize())
                cmd = self.command_queue.get()
                self.command_queue.task_done()
                cmd.send()
                time.sleep(0.5)
